package com.zyy.dept.controller;

import com.zyy.dept.entity.Dept;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @Description: 类描述
 * @Author: zyy
 * @Date: 2023/02/12 11:30
 */
@RestController

@RequestMapping("/consumer")
public class DeptControllerController {

    private final RestTemplate restTemplate;


    public DeptControllerController(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    /**
     * http://localhost:8001/dept/addDept
     */
    private static final String REST_URL_PREFIX = "http://localhost:8001";


    @RequestMapping(value = "/getAll", method = RequestMethod.GET)
    public List<Dept> getAll() {
        return restTemplate.getForObject(REST_URL_PREFIX + "/dept/getAll", List.class);
    }

    @RequestMapping(value = "/get/{deptNo}", method = RequestMethod.GET)
    public Dept getByNo(@PathVariable long deptNo) {
        return restTemplate.getForObject(REST_URL_PREFIX + "/dept/get/" + deptNo, Dept.class);
    }

    @RequestMapping(value = "/addDept", method = RequestMethod.POST)
    public Boolean addDept(@RequestBody Dept dept) {
        return restTemplate.getForObject(REST_URL_PREFIX + "/dept/addDept", Boolean.class, dept);
    }
}
